home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 3 code / ISO 9660 & High Sierra / iso9660 ƒ / DialogUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-16  |  2.1 KB  |  87 lines  |  [TEXT/KAHL]

  1. /*
  2. from engber@gumball.ils.nwu.edu (Mike Engber):
  3.  
  4. Thanks for all the replys to my centering DLOG/ALRT question. I used the
  5. best ideas to synthesize my solution which I think elegant enough to be
  6. worth sharing. Attached are the relevant portions of my .h & .c files.
  7.  
  8. A couple of notes:
  9.  
  10. Several people`s solutions burned in the rsrc ids of the standard
  11. file dialogs. You may want to note that there are named constants for
  12. these values: putDlgID  & getDlgID.
  13.  
  14. All the solutions I was sent used screenBits.bounds. Is this what you
  15. want in a multi-monitor situation? If not, what should you do?
  16.  
  17. Feel free to use/modify/comment-on this code, especially if you notice
  18. any bugs or questionable practices.
  19.  
  20. -ME
  21. */
  22.  
  23. /* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
  24.  
  25.  
  26. /* DialogUtils.c */
  27.  
  28. #include "DialogUtils.h"
  29.  
  30. static void DU_CenterRect(Rect* rect_p){
  31. /*
  32.  * Aligns *rect_p wrt screenBits.bounds - LR centered & in upper 1/3
  33.  */
  34.  
  35.     /* exactly centered */
  36.     OffsetRect(rect_p,
  37.             (screenBits.bounds.right + screenBits.bounds.left)/2 -
  38.                 (rect_p->right + rect_p->left)/2
  39.         ,
  40.             (screenBits.bounds.top + screenBits.bounds.bottom)/2 -
  41.                 (rect_p->top + rect_p->bottom)/2
  42.         );
  43.     
  44.     /* up a bit */
  45.     OffsetRect(rect_p,0, 
  46.         GetMBarHeight() - 2*(rect_p->top - screenBits.bounds.top)/3);
  47. }
  48.  
  49. static Point DU_Where(short rsrcId){
  50. /*
  51.  * Returns centering point for the topLeft corner of a dialog.
  52.  */
  53.     Handle  h = GetResource('DLOG',rsrcId);
  54.     Rect    r = {0,0,0,0};
  55.     if(h){
  56.         r = *((Rect*)(*h));
  57.         DU_CenterRect(&r);
  58.         ReleaseResource(h);
  59.     }
  60.     return topLeft(r);
  61. }
  62.  
  63. Point DU_StdPutWhere(void){
  64.     return DU_Where(putDlgID);
  65. }
  66.  
  67. Point DU_StdGetWhere(void){
  68.     return DU_Where(getDlgID);
  69. }
  70.  
  71. static short DU_Center(ResType type, short rsrcId){
  72. /*
  73.  * Reads in an 'ALRT' or 'DLOG' rsrc template & centers it's display Rect.
  74.  */
  75.     Handle  h = GetResource(type,rsrcId);
  76.     if(h) DU_CenterRect((Rect*)(*h));
  77.     return rsrcId;
  78. }
  79.  
  80. short DU_CenterALRT(short rsrcId){
  81.     return DU_Center('ALRT',rsrcId);
  82. }
  83.  
  84. short DU_CenterDLOG(short rsrcId){
  85.     return DU_Center('DLOG',rsrcId);
  86. }
  87.